<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/jsp/include/taglib.jsp"%>
<%@ include file="/jsp/include/headform.jsp"%>
<%@ page isELIgnored="false" %>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<html lang="en">
<head>
<base href="<%=basePath%>" />
<meta charset="utf-8" />
<title>Untitled Document</title>
<link rel="stylesheet" href="${ctxStatic}/css/list.css" />
<script type="text/javascript" src="${ctxStatic}/js/jquery.cookie.js"></script>
<!--[if IE 6.0]>
           <script src="js/iepng.js" type="text/javascript"></script>
           <script type="text/javascript">
                EvPNG.fix('div, ul, ol, img, li, input, span, a, h1, h2, h3, h4, h5, h6, p, dl, dt');
           </script>
       <![endif]-->

<script type="text/javascript">
		
		Global.ticket = ${sessionScope.LOGIN_USER.id}+'_'+1;
		Global._resourceRootId = 1;
		Global._ruleTypeId = 1;
		Global._pType = 'user';
		Global._nType = 'resource';
		Global.topResourceId = [];
		Global.respaths = [];
		Global.permissionIds = [];
		 $(document).ready(function () {
			 $("#logout").click(function(){
		         if(confirm("您确认退出系统吗？")){
		           $.cookie('chron_token', '', {expires:-1,path:'/'}); // 删除 cookie
		           window.top.location="http://10.1.14.20:8088/portal/logout.jsp";
				 }
				});
			 $.ajax({
					url : "api/login/"+Global._ruleTypeId+"?loginName=${sessionScope.LOGIN_USER.loginName}&password=${sessionScope.LOGIN_USER.password}" ,
					type : "post",
					async : false,
					dataType:'json',
					success : function (rtn){
						var _title="";
						var topResource = [];
						if(rtn && rtn.info.success){
							var data = rtn.data.permission;
							if(data != null){
								for(var i = 0 ; i < data.length ; i ++){
									var d = data[i];
									Global.permissionIds.push(d.resourceId);
									Global.respaths.push(d.resourcePath);
									//getAllPermissionIds(d.resourceId);
								}
								
/* 								for(var i = 0 ; i < data.length ; i ++){
									var d = data[i]; */
									var allPri = $.inArray("/**",Global.respaths);
									if(allPri != -1){
										$.ajax({
							 			   url: "api/resource/" + Global._resourceRootId + "/child?ticket=" + Global.ticket ,
							 			   type:'get',
							 			   dataType:'json',
							 			   async:false,
							 			   error:function(){alert('系统连接失败，请稍后再试！')},
							 			   success:function(result){
							 				   if(result.info.success==false){
							 					   alert('权限异常，请联系管理员！');
							 				   }else{
							 						$.each(result.data,function(key, value){
							 							if(value.node.type=='module'){
							 								_title += "<a id=\"level1Menu\" onclick=\"javascript:top.selectLeftMenu("+value.node.id+",'"+Global.permissionIds+"',"+true+")\">"+value.node.name+"</a> ";
							 							}
							 						});
							 				   }
							 			   }
							 		   });
									}else{
										for(var i = 0 ; i < data.length ; i ++){
											var d = data[i];
				 							if(d.resourceType=='module'){
				 								_title += "<a id=\"level1Menu\" onclick=\"javascript:top.selectLeftMenu("+d.resourceId+",'"+Global.permissionIds+"',"+false+")\">"+d.resourceName+"</a> ";			 									
				 							}										
										}
									}
									
/* 								} */
							}
						}
					  	 $(".menu").append(_title);	
					}
				});
		 });
		 
		 function getAllPermissionIds(resourceId){
			$.ajax({
				   url:'api/relation',
				   data:{
					   ptype:'resource',
					   ntype:'resource',
					   nid:resourceId,
					   removed:0,
					   ruleTypeId:Global._ruleTypeId
				   },
				   type:'get',
				   dataType:'json',
				   async:false,
				   error:function(){alert('系统连接失败，请稍后再试！')},
				   success:function(result){
				   var sdata = result.data;
				   if(sdata != null){
						for(var i = 0 ; i < sdata.length ; i ++){
							var parentId = sdata[i].pid;
							if($.inArray(parentId,Global.permissionIds)==-1){
								Global.permissionIds.push(parentId);
							}
						}
					  }
				   }
			   });
		 }
		 
		 function reverseTree(resourceId){
			 var topResource;
			 $.ajax({
					url : "api/" + Global._nType + "/" + resourceId + "/reverseTree?ticket=" + Global.ticket ,
					type : "get",
					async : false,
					dataType:'json',
					success : function (rtn){
						
						if(rtn && rtn.info.success){
							var data = rtn.data;
							if(data != null){
								for(var i = 0 ; i < data.length ; i ++){
									var d = data[i];
									if(d.node.type=='module' && $.inArray(d.node.id,Global.topResourceId)==-1){
										Global.topResourceId.push(d.nid);
										topResource=d;
										return topResource;
									}
								}
							}
						}
					}
				});
			 return topResource;
		 }
		 
		 
		function doLogout(){
			ppaewin.confirm("确认退出？", function(){
			$("#logoutForm").submit();
			}, function(){});
		}
</script>
</head>

<body class="bg-color">
<div class="logo-bg"> <span class="logo-title"></span>
  <ul>
    <li class="user-login"></li>
   <form action="<%=path %>/ppae/doLogout.do" id="logoutForm"> <li class="exit" onclick=""  ></li> </form>
  </ul>
<%--   当前用户：${sessionScope.LOGIN_USER.name} --%>
<%--   当前用户：${sessionScope.LOGIN_USER.name} | <a href="http://10.1.14.20:8088/portal/logout.jsp" target="_top" class="logout" title="退出">退出</a> --%>
</div>
<!-- <div class="menu"> <a href="#">统一用户管理</a> <a href="#">统一权限管理</a> <a href="#">应用系统管理</a> <a href="#">修志系统</a> </div> -->
<div class="menu"> </div>
<!--   <div class="left-menu-bg"> </div> -->
</div>
</body>
</html>
